# class dotxts():
#     def dotxt(self,f):
#         with open(f,'r',encoding='utf-8') as ff:
#             print(ff.read())
import openpyxl
from openpyxl import Workbook
from openpyxl.worksheet.worksheet import Worksheet


class dotexts():
    def dotxt(self):
        f = r'D:\2501\demo0\tmp\111.jpg'
        ff = open(f, 'rb')
        return ff.read()


# class dotexts():
#     def dotxt(self,f,m):
#         # f = r'D:\2501\demo0\tmp\1.txt'
#         ff = open(f,m)
#         print(ff.read())
# class dotexts():
#     def dotxt(self,f,m,s,isUTF=False):
#         # f = r'D:\2501\demo0\tmp\1.txt'
#         if isUTF:
#             ff = open(f,m,encoding='utf-8')
#         else:
#             ff = open(f,m)
#         ff.write(s)

class dotexts1():
    def dotxt(self, f, m, s, isUTF=False):
        # f = r'D:\2501\demo0\tmp\1.txt'
        if isUTF:
            with open(f, m, encoding='utf-8') as ff:
                ff.write(s)
        else:
            with open(f, m) as ff:
                ff.write(s)


class DoExe():
    def doExeRead(self, f, a1, c, d, e, g):
        #  生成文件对象
        # workbook = openpyxl.load_workbook(f)
        # print(workbook.get_sheet_names)
        # 获取表名
        # print(workbook.sheetnames)
        wk: Workbook = openpyxl.load_workbook(f)
        # 获取sheet对象,

        st: Worksheet = wk[a1]
        # print(st)
        # print(st.rows)
        # print(st.values)
        # ls = [i for i in st.rows]
        ls = [i for i in st.iter_rows(c, d, e, g, values_only=True)]
        return ls
        # print(ls)
        # ls = [i for i in st.values]
        #
        # print(ls)
        #
        # print(type(st))

    def doExeWrite(self, f):
        # 已有文件
        wk = openpyxl.load_workbook(f)
        # print(wk.sheetnames)
        # print(type(wk.worksheets[2]))
        she = wk.worksheets[2]
        she.cell(1, 1, 'append')
        wk.save(f)

    def doNoFile(self, f):
        # 没有文件
        wk = openpyxl.Workbook()
        cj = wk.create_sheet('ttt')
        cj.cell(1, 1, 123)
        wk.save(f)

        # she:Worksheet = wk['Sheet3']
        # print(type(she))


if __name__ == '__main__':
    # f = r'D:\2501\demo0\tmp\t.xlsx'
    f = r'D:\2501\cym\jisuanqi\jia.xlsx'
    e = DoExe()
    # e.doExeRead(f)
    # e.doExeWrite(f)
    # e.doNoFile(f)
    # dotxts().dotxt(r'D:\2501\demo0\tmp\1.txt')
    # s = dotexts().dotxt()
    # print(s)
    # f = r'D:\2501\demo0\tmp\p.jpg'

    # f=r'D:\2501\demo0\tmp\111.jpg'
    # dotexts().dotxt(f,'rb')
    # f= r'D:\2501\demo0\tmp\1.txt'
    # f = r'D:\2501\demo0\tmp\2.txt'
    # s = 'hello,python\n'
    # dof=dotexts()
    # dof.dotxt(f,'a',s,True)
    # dof=dotexts1()
    # dof.dotxt(f,'wb',s)
